import c_screener_mode
import pygame

class cCredits(c_screener_mode.c_screener_mode):
	def __init__(self):
		c_screener_mode.c_screener_mode.__init__(self)
		self.font = pygame.font.SysFont("Courier", 40)
		self.text=""
		self.dy=0
	def fill_via_file(self):
		source=open('locali\\'+self.locali+'\\'+self.file)
		#read it
		self.text=source.read().decode('utf-8')
		#print "height is",self.text.count('\n')*40
		source.close()
	def draw(self):
		self.gears.screen.fill((0,0,200))
		self.gears.screen.blit(self.creditsSurface,(0,self.dy))
		pygame.display.flip()
		pass
	def do(self):
		g=pygame.event.get()
		self.draw()
		pygame.time.wait(1000/24)
		self.dy=self.dy-1
		if self.creditsSurface.get_height()+self.dy<0:
			self.switch_mode(None)
	def locali_check(self):
		if self.locali!=self.gears.locali:
			self.locali=self.gears.locali
			self.fill_via_file()
	def makeCredits(self):
		h=self.font.render('l', True, (240,1,1), (255, 0, 255)).get_height()
		H=self.text.count('\n')*h+h
		print "height is",H,h
		self.creditsSurface=pygame.Surface((self.window_size[0],H))
		self.creditsSurface.fill((255,0,255))
		self.creditsSurface.set_colorkey((255,0,255))
		text=self.text.split('\n')
		i=0
		for t in text:
			tex=self.font.render(t, True, (240,1,1), (255, 0, 255))
			w=0.5*(self.creditsSurface.get_width()-tex.get_width())
			self.creditsSurface.blit(tex,(w,i))
			i=i+h
		#pass
	def configure_window(self):
		self.window_size=self.gears.screen_size
		print self.window_size
		print self.gears.screen.get_size()
		#self.creditsSurface=pygame.Surface(self.window_size)
	def activate(self):
		self.makeCredits()
		self.dy=10